package visiopuce;

import java.util.ArrayList;
import java.util.Date;

import visiopuce.objets.Alteration;
import visiopuce.objets.Historique;
import visiopuce.objets.Recherche;
import visiopuce.objets.Utilisateur;
import visiopuce.service.HistoriqueServiceImpl;

public class ApplicationContexte {

	private Utilisateur utilisateur;
//	public static final String REPERTOIRE_RESULTAT = "C:\\Users\\Manon\\Documents\\cytogalaxieRepo\\resultats\\";
//	public static final String REPERTOIRE_MODEL = "C:\\Users\\Manon\\Documents\\cytogalaxieRepo\\models\\";
//	public static final String REPERTOIRE_PROTOCOLE = "C:\\Users\\Manon\\Documents\\cytogalaxieRepo\\protocoles\\";
//	public static final String FICHIER_PRESCRIPTION = "C:\\Users\\Manon\\Documents\\cytogalaxieRepo\\Dossiers.xml";
//	public static final String REPERTOIRE_COTATION = "C:\\Users\\Manon\\Documents\\cytogalaxieRepo\\cotation\\";
//	public static final String REPERTOIRE_FISH = "C:\\Users\\Manon\\Documents\\cytogalaxieRepo\\FISH\\";
//	public static final String REPO = "file:///c:/Users/Manon/Documents/cytogalaxieRepo";
//	public static final String REPERTOIRE_DOCUMENT = "C:\\Users\\Manon\\Documents\\cytogalaxieRepo\\documents\\";
//	public static final String REPERTOIRE_PRESCRIPTION = "C:\\Users\\Manon\\Documents\\cytogalaxieRepo\\prescriptions\\";
//	public static final String REPERTOIRE_PUCE = "C:\\Users\\Manon\\Documents\\cytogalaxieRepo\\agilent\\";

//	public static final String REPERTOIRE_RESULTAT = "W:\\DeveloppementCytogenetique\\resultats\\";
//	public static final String REPERTOIRE_MODEL = "T:\\Centres de Responsabilite\\Naiss Path Femme\\Genetique Chromosomique\\Cytogenetique\\cytogalaxie\\models\\";
//	public static final String REPERTOIRE_FISH = "W:\\PhotosCentreRefGenetique\\Puces\\Patients à étudier en FISH\\";
//	// public static final String REPERTOIRE_PROTOCOLEss =
//	// "T:\\Centres de Responsabilite\\Naiss Path Femme\\Genetique Chromosomique\\Cytogenetique\\cytogalaxie\\protocoles\\";
//	public static final String REPERTOIRE_PROTOCOLE = "W:\\DeveloppementCytogenetique\\protocoles\\";
//	public static final String FICHIER_PRESCRIPTION = "W:\\PhotosCentreRefGenetique\\Prescriptions médicales\\ne pas supprimer ni ouvrir ni modifier\\Dossiers.xml";
//	public static final String REPERTOIRE_COTATION = "T:\\Centres de Responsabilite\\Naiss Path Femme\\Genetique Chromosomique\\Cytogenetique\\cotations\\";
//	public static final String REPO = "file:/W:/DeveloppementCytogenetique/cytogalaxie/updateRepo/repository/";
//	public static final String REPERTOIRE_PRESCRIPTION = "T:\\Centres de Responsabilite\\Naiss Path Femme\\Genetique Chromosomique\\Cytogenetique\\prescriptions\\";
//	public static final String REPERTOIRE_DOCUMENT = "W:\\DeveloppementCytogenetique\\documents\\";

	public static final String REPERTOIRE_RESULTAT = "\\\\172.20.1.7\\fs_applis\\Applis\\DeveloppementCytogenetique\\resultats\\";
	public static final String REPERTOIRE_MODEL = "\\\\172.20.1.7\\fs_applis\\Applis\\DeveloppementCytogenetique\\models\\";
	public static final String REPERTOIRE_FISH = "\\\\172.20.1.7\\fs_applis\\Applis\\PhotosCentreRefGenetique\\Puces\\Patients à étudier en FISH\\";
	// public static final String REPERTOIRE_PROTOCOLEss =
	// "T:\\Centres de Responsabilite\\Naiss Path Femme\\Genetique Chromosomique\\Cytogenetique\\cytogalaxie\\protocoles\\";
	public static final String REPERTOIRE_PROTOCOLE = "\\\\172.20.1.7\\fs_applis\\Applis\\DeveloppementCytogenetique\\protocoles\\";
	public static final String FICHIER_PRESCRIPTION = "\\\\172.20.1.7\\fs_applis\\Applis\\PhotosCentreRefGenetique\\Prescriptions médicales\\ne pas supprimer ni ouvrir ni modifier\\Dossiers.xml";
	public static final String REPERTOIRE_COTATION = "\\\\172.20.1.7\\fs_applis\\Applis\\DeveloppementCytogenetique\\cotations\\";
	public static final String REPO = "file://172.20.1.7/fs_applis/Applis/DeveloppementCytogenetique/cytogalaxie/updateRepo/repository/";
	public static final String REPERTOIRE_PRESCRIPTION = "\\\\172.20.1.7\\fs_util\\Utilsiateurs\\Centres de Responsabilite\\Naiss Path Femme\\Genetique Chromosomique\\Cytogenetique\\prescriptions\\";
	public static final String REPERTOIRE_DOCUMENT = "\\\\172.20.1.7\\fs_applis\\Applis\\DeveloppementCytogenetique\\documents\\";
	public static final String REPERTOIRE_PUCE = "\\\\17.20.1.7\\bio\\cytogenetique\\puces\\agilent\\";
	
	private Recherche rechercheEnCours;
	private Alteration region;

	public static final String SECTEUR_PUCE_PRENATAL = "Puce prénatale";
	public static final String SECTEUR_PUCE_POSTNATAL = "Puce postnatale";
	public static final String SECTEUR_PRENATAL = "Prénatal";
	public static final String SECTEUR_POSTNATAL = "Postnatal";
	public static final String SECTEUR_BANQUE = "Banque";
	public static final String SECTEUR_CELLULES = "Cellules souches";
	public static final String SECTEUR_FOETO = "Foetopathologie";
	public static final String SECTEUR_PUCE_FOETO = "Puce foetopathologie";

	public static final String[] quantiteSang = { "", "plein", "3/4", "moitié", "1/4" };
	public static final String[] quantiteFibro = { "", "gros morceau", "petit morceau" };
	public static final String[] quantiteLA = { "", "<10 mL", "10 à 20 mL", ">20 mL" };
	public static final String[] quantiteCulot = { "", "+/-", "+", "++", "+++" };
	public static final String[] quantiteADN = { "ng/μL" };
	public static final String[] quantiteVC = { "", ">20 mg", "10 à 20 mg", "<10 mg" };

	public static final String[] quantiteAutre = { "", "g", "ml", "μL", "ng/μL", "mg" };
	public static final String[] tubeSang = { "", "hépariné", "EDTA", "sérum", "Paxgene", "Tube sec", "autre" };

	public static final String[] qualiteSang = { "", "absence de caillot", "présence de caillot", "tube cassé" };
	public static final String[] qualiteLA = { "", "clair", "rosé", "hémoragique", "verdâtre", "blanchâtre", "autre" };
	public static final String[] qualiteCulot = { "", "clair", "rosé", "rouge", "autre" };
	public static final String[] qualiteFibro = { "", "mou", "dur", "ferme", "visqueux" };

	public static final String[] qualiteMacroVC = { "correct", "sanglant", "nacré", "marron", "graisseux", "autre" };
	public static final String[] qualiteMicroVC = { "correct", "caduque", "sanglant", "friable", "autre" };

	public static final String[] droits = { "admin", "personne", "tNSejour", "tIPP", "tNom", "tPrenom", "tAutrePheno", "dNaissance", "btnRadioSexe", "btnCheckPhenotype", "btnRadioFoetus", "prelevement", "btnRadioSecteur", "tNumeroPrelevement", "tInfoIndication", "btnCheckRecherche", "btnCheckDpi",
			"comboTypeEchantillon", "comboTypeIndication", "comboDerive", "datePrelev", "dateReception", "champPrenatal", "champLA", "champVC", "champFibro", "champSang", "champADN", "document", "analyse", "btnGenererResultat", "btnDossierUrgent", "comboPrescripteur", "comboTypeAnalyse", "tUrgent",
			"tUFExec", "tUFPrescr", "tNomPrenomAutrePresc", "comboTechnicienne", "dateTechnique", "puce", "tParametresPuce", "dEnregistrement", "btnSexePuce", "tFichierQc", "btnFichierQC", "qcs", "btnChoisirCettePuce", "btnFichierSegement", "comboLogiciel", "comboFeuillePuce", "comboModelePuce",
			"comboMarquePuce", "dPreAna", "tPreAna", "dRelecture", "tRelecture", "btnCheckReunion", "tReunion", "dReunion", "comboAnnotateur", "comboSignataire", "alteration", "tConfidence", "tLog2R", "tNbCopie", "tNbMq", "tSondeFin", "tSondeDebut", "tFin", "tDebut", "comboChr", "tGenesInteret",
			"tCommentairePA", "comboPreAna", "comboNotePA", "comboQualifPA", "tCommentaireS", "comboSign", "comboNoteS", "comboQualifS", "btnCheckVerifBM", "btnCheckVerifFISH", "btnCheckPrFormule", "comboAnnotationFinale", "resultat", "dateRendu", "comboTypeRendu", "btnCheckMosaique", "tFormule",
			"btnRadioResultat", "btnRadioHerite", "btnCheckChromosomes", "tCommentaire", "renduPuce", "dVerification", "dRedaction", "renduBM", "renduFish", "tResolutionCaryoTech", "tFormuleTech", "tRemarqueTech", "cIndexMito", "clChr", "cCytoplasme", "cMitosesEclat", "cBandeR", "cBandeG",
			"tResolutionCaryo", "btnMarquage", "tMitosesClassees", "tMitosesExaminees", "tColonies", "tSondeFish", "tNbMitoseFish", "tNbNoyauxFish", "cotation", "champMicroSat", "envoyerCotation", "btnSigne", "comboVerificateur", "nonConf" };

	public static final String[] notes = { "0", "1", "2", "3", "4", "5" };

	public static final String[] chr = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "X", "Y" };
	public static final String nf2AV = "#,###.##";
	public static final String nf4AV = "#,###.####";
	public static final String nf4AVneg = "-#,###.####";
	public static final String nfEntier = "###,###,###,###";
	public static final String nf4Entier = "####";
	public static final String[] annotations = { "", "VOUS", "Pathogène", "Polymorphisme" };

	public static final String[] resolutionCaryo = { "", "900 bandes", "850 bandes", "700 bandes", "550 bandes", "400-550 bandes", "400 bandes", "300 bandes" };

	public static final String[] marquageCaryo = { "GTG", "RHG", "Q", "bandes C", "NOR" };

	public static final String[] contamination = { "Oui", "Faible contamination", "Pas de contamination" };

	public static final String[] typeFish =  { "autre", "T21 : LSI 13/21 Aquarius",  "22q11 : TUPLE1/TBX1", "FISH XY : DXZ1(Xq10)/DYZ3 (Yq10) Vysis", "FISH dif sex : DXZ1(Xq10)/DYZ1 (Yq12) Aquarius" ,
		"FISH Prader Willi 15q11 : SNRPN/UBE3A Aquarius" , "Retard statural fille : DXZ1(Xq10) Métasystems",
		"Retard statural garçon : DXZ1(Xq10)/DYZ3 (Yq10) Aquarius", "Retard statural SHOX fille : SHOX(Xp22)/DXZ1(Xq10)/DYZ1(Yq12) Aquarius", "Retard statural SHOX garçon : SHOX(Xp22/Yp11)/DXZ1(Xq10)/DYZ1(Yq12) Aquarius"};
	
	
	public static final String[] acceptations = { "Accepté", "Accepté sous réserve de complément d'information", "Accepté sous réserve de confirmation d'identité", 
		"Accepté, mais réalisé en heures ouvrables si le delai de conservation est compatible", "Refusé" };
	
	public static final String[] actionsCorrectives = { "Demande de confirmation d'identité", "Demande d'un nouvel échantillon", "Echantillon réacheminé",
		"Prescription modifiée", "Service prévenu par téléphone", "Tentatives téléphoniques infructueuses" };
	
	
	public static final String CONCENTRATION_ADN_M = "273,0";
	public static final String CONCENTRATION_ADN_F = "135,0";
	
	
	
	// pré-ana
	public static final ArrayList<String> cotationReception = new ArrayList<String>() {
		{
			add("A9005");
			add("AN200");
		}
	};
	// conservation + technique de puce
	public static final ArrayList<String> cotationPuce = new ArrayList<String>() {
		{
			add("AQ048");
			add("AB034");
			;
		}
	};
	// analyse puce
	public static final ArrayList<String> cotationAnalysePuce = new ArrayList<String>() {
		{
			add("AN211");
			add("AN215");
			add("AN216");
		}
	};



	/** Instance unique pré-initialisée */
	private static ApplicationContexte INSTANCE = new ApplicationContexte();
	public static String[] resolution;

	/** Point d'accès pour l'instance unique du singleton */
	public static ApplicationContexte getInstance() {
		return INSTANCE;
	}

	public static boolean isOut(String libelleTypeQc, Double valeur) {
		String[] tab = libelleTypeQc.split("\\(");
		boolean estOut = false;
		if (valeur != null) {
			if (tab.length > 1) {
				String sens = tab[1].substring(0, 1);
				if (sens.equals(">")) {
					if (tab[1].substring(tab[1].length() - 2, tab[1].length() - 1).equals("%")) {
						if (valeur < Double.parseDouble(tab[1].substring(1, tab[1].length() - 2))) {
							estOut = true;
						}
					} else {
						if (valeur < Double.parseDouble(tab[1].substring(1, tab[1].length() - 1))) {
							estOut = true;
						}
					}
				} else if (sens.equals("<")) {
					if (tab[1].substring(tab[1].length() - 2, tab[1].length() - 1).equals("%")) {
						if (valeur > Double.parseDouble(tab[1].substring(1, tab[1].length() - 2))) {
							estOut = true;
						}
					} else {
						if (valeur > Double.parseDouble(tab[1].substring(1, tab[1].length() - 1))) {
							estOut = true;
						}
					}
				}
			}
		} else {
			estOut = true;
		}
		return estOut;
	}

	/** Constructeur privé */
	private ApplicationContexte() {
	}

	public Recherche getRechercheEnCours() {
		return rechercheEnCours;
	}

	public Alteration getRegionRechercheEnCours() {
		return region;
	}

	public Utilisateur getUtilisateur() {
		return utilisateur;
	}

	public void setRechercheEnCours(Recherche rechercheEnCours) {
		this.rechercheEnCours = rechercheEnCours;
	}

	public void setRegionRechercheEnCours(Alteration region) {
		this.region = region;
	}

	public void setUtilisateur(Utilisateur utilisateur) {
		Historique h = new Historique();
		h.setDate(new Date());
		h.setRequete("Connexion " + utilisateur.toString());
		h.setUtilisateur(utilisateur);
		HistoriqueServiceImpl.getInstance().save(h);
		this.utilisateur = utilisateur;
	}

	public String valideDate(Date date) {
		String message = "";
		if (date.getYear() < 1920 && date.getYear() > 2030) {
			message = "L'année de la date n'est pas conforme";
		}
		if (date.getMonth() < 1 && date.getMonth() > 12) {
			message = "Le mois n'est pas conforme";
		}
		if (date.getDay() < 1 && date.getDay() > 31) {
			message = "Le mois n'est pas conforme";
		}
		return message;
	}

}
